<?php namespace system\tag;
use houdunwang\view\build\TagBase;

class Common extends TagBase {
	/**
	 * 标签声明
	 * @var array
	 */
	public $tags = [
			'line' => [ 'block' => false ],
        'prev' => [ 'block' => false ],
        'next' => [ 'block' => false ],
        'category'  => [ 'block' => true , 'level' => 4 ] ,
        'slide'  => [ 'block' => true , 'level' => 4 ] ,
        'arclist' => ['block' => true ,'level' =>4]
	];
	//line 标签
	public function _line( $attr, $content, &$view ) {
		return 'link标签 测试内容';
	}

	//tag 标签
    //tag 标签
    public function _category ( $attr , $content , &$view )
    {
        $pid = isset($attr['pid']) ? $attr['pid']  : -1;
        //看解析成了什么，看编译文件
        //转义不转义变量
        $str = <<<str
				<?php
					\$db= Db::table('category');
					if($pid>=0){
						\$db->where('cate_pid',$pid);
					}
					\$data = \$db->get();
					foreach(\$data as  \$key => \$field):
						\$field['url'] = __ROOT__ . '/c/' . \$field['cate_id'] . '.html';
				?>
					$content
				<?php
					endforeach
				?>
str;

        return $str;
    }
    public function  _slide($attr , $content , &$view ){

        //看解析成了什么，看编译文件
        //转义不转义变量
        $str = <<<str
				<?php
					\$db= Db::table('slide');
					\$data = \$db->get();
					foreach(\$data as \$key => \$field):
		
				?>
					$content
					
				<?php
					endforeach
				?>
str;

        return $str;

    }
    public function _arclist($attr, $content, &$view)
    {
        $cid = isset($attr['cid']) ? $attr['cid'] : -1;
        $thumb = isset($attr['thumb']) ? $attr['thumb'] : -1;
        $str = <<<str
				<?php
					\$db= Db::table('article');
					if('$cid'>=0){
					    \$db->whereIn('cate_id',explode(',','$cid'));
					}
					if($thumb==1){
					    \$db->where('arc_thumb','<>','');
					}
					\$data = \$db->get();
					foreach(\$data  as \$key=> \$field):
					    \$field['arc_thumb'] = __ROOT__ . '/' .  \$field['arc_thumb'] ;
					    \$field['url'] = __ROOT__ . '/' .  \$field['arc_id'] . '.html' ;
				?> 
					$content
				<?php
					endforeach
				?>
str;

        return $str;
    }

    //下一篇
    public function _next ( $attr , $content , &$view )
    {
        $str = <<<str
			<?php
			\$arc_id = Request::get('arc_id');
			\$data = Db::table('article')->where('arc_id','>',\$arc_id)->orderBy('arc_id','ASC')->first();
			if(\$data){
				echo "<a href='".\$data['arc_id'].".html"."'>{\$data['arc_title']}</a>";
			}else{
				echo '无';
			}
			?>
str;

        return $str;
    }

    //上一篇
    public function _prev ( $attr , $content , &$view )
    {
        $str = <<<str
			<?php
			\$arc_id = Request::get('arc_id');
			\$data = Db::table('article')->where('arc_id','<',\$arc_id)->orderBy('arc_id','DESC')->first();
			if(\$data){
				echo "<a href='".\$data['arc_id'].".html"."'>{\$data['arc_title']}</a>";
			}else{
				echo '无';
			}
			?>
str;

        return $str;
    }

}